<template>
  <s-layout id="layout" :title="'报名列表'" navbar="normal" leftIconColor="#333" :autoBack="false" :bgColor="state.bgColor"
    :tabbarshow='false' :titleStyle="{ color: '#333', fontSize: '32rpx' }">
    <view class="call_on list_box" :style="{ paddingTop: (safeAreaInsets?.top + 44) + 'px' }">
      <scroll-view scroll-y class="comprehensive" v-if="list.length" @scrolltolower='listScrolltolower'
        show-scrollbar="true" :refresher-enabled="isOpenRefresh" :refresher-triggered="triggered"
        :refresher-threshold="100" refresher-background="white" @refresherpulling="onPulling"
        @refresherrefresh="onRefresh" @refresherrestore="onRestore" @refresherabort="onAbort" @scroll="onScroll">
        <view class="item_wrap">
          <view class="item" v-for="(item, index) in list" :key="index">
            <view class="flex">
              <image class="flex_avater" :src="`${baseUrl}` + item.user.avatar" mode="scaleToFill" />
              <view class="item_left">
                <view class="item_left_box">
                  <text class="names">{{ item.user.nickname }}的报名申请</text>
                </view>
                <view class="item_left_box">
                  <text class="name">{{ item.post }}</text>
                </view>
              </view>
              <view class="item_right">
                <view :class="item.state == 0 ? 'yellow' : item.state == 1 ? 'green'
    : item.state == 2 ? 'red' : item.state == 3 ? 'blue' : 'status'" v-if="item.status !== 0">
                  {{ item.state == 0 ? '待审批' : item.state == 1 ? '已审批'
    : item.state == 2 ? '已拒绝' : item.state == 3 ? '审批中' : '' }}
                </view>
              </view>
            </view>
            <view class="flex">

              <view class="item_left">
                <view class="item_left_box">
                  <view class="box_name">申请时间 </view>
                  <text class="box_content">{{ formatDate(item.createtime) }}</text>
                </view>
                <view class="item_left_box">
                  <view class="box_name">申请岗位 </view>
                  <text class="box_content">{{ item.title }}</text>
                </view>
              </view>
              <view class="item_right" @click="lookDetail(item)">
                <text class="name">查看详情</text>
                <u-icon size="10" name="arrow-right" color="#0038F7"></u-icon>
              </view>
            </view>

          </view>

        </view>
        <!-- 正在加载组件 -->
        <view>
          <s-loadmore-gather :current_page="listPage" :last_page="listlast_page" ref="loadmoreRef"></s-loadmore-gather>
        </view>

      </scroll-view>

      <u-empty v-else mode="list" icon="http://cdn.uviewui.com/uview/empty/list.png" text="暂无内容"
        marginTop="50%"></u-empty>
    </view>
  </s-layout>
  <!-- 底部保存按钮 -->
  <view>
    <s-button @netWork="submitForm" :text="state.text" />
  </view>
</template>

<script setup>
import { baseUrl } from '@/sheep/config';
import sheep from '@/sheep';
import { onLoad, onShow } from "@dcloudio/uni-app";
import { ref, reactive } from 'vue';
import { formatDate } from '@/utils/fn.js';
const { safeAreaInsets } = uni.getSystemInfoSync()
const state = ref({
  bgColor: '#fff',
  text: '添加报名'
})
const list = ref([])
const listPage = ref()
const listlast_page = ref();
const listpagenumber = ref(1);
onShow((options) => {
  list.value = [];
  listpagenumber.value = 1;
  getListDetail()
})

// 1.
const loadmoreRef = ref()
//数据请求

const getListDetail = () => {
  let obj = {
    state: '0,3',
  };
  let params = {
    filter: JSON.stringify(obj),
    op: JSON.stringify({
      state: 'in',
    }),
    page: listpagenumber.value,

  };
  sheep.$api.recruitment.getRecruitmentApplyApplyIndex(params).then((res) => {
    list.value = [...list.value, ...res?.data.rows];
    listPage.value = res.data.current_page
    listlast_page.value = res.data.last_page
  });

}

//滚动触底
const listScrolltolower = () => {
  loadmoreRef.value.PopupScrolltolower()
  if (listPage.value < listlast_page.value) {
    listpagenumber.value += 1;
  } else {
    return;
  }
  getListDetail();
};
const lookDetail = (item) => {
  sheep.$router.go('/subpackage/staff/workbench/recruitment/recruitment_detail', {
    ids: item.id,
  page:'apply'
  });
}
// 页面下拉刷新
const freshing = ref(false)
const triggered = ref(false)
const isOpenRefresh = ref(true)  // 是否开启下拉
// 自定义下拉刷新控件被下拉
const onPulling = (e) => {
  if (e.detail.deltaY < 0) return  // 防止上滑页面也触发下拉
  triggered.value = true;
}
// 自定义下拉刷新被触发
const onRefresh = () => {
  if (freshing.value) return;
  freshing.value = true;
  setTimeout(() => {
    listpagenumber.value = 1;
    list.value = []
    triggered.value = false;
    freshing.value = false;
    getListDetail();
  }, 500);
}
// 自定义下拉刷新被复位
const onRestore = () => {
  triggered.value = 'restore'; // 需要重置
  // console.log("onRestore");
}
// 自定义下拉刷新被中止
const onAbort = () => {
  // console.log("onAbort");
}

</script>
<style lang="scss" scoped>
@import '../compentns/publiclist.scss';

// 滚动
.comprehensive {
  width: calc(100% - 40rpx);
  background-color: rgba(0, 0, 0, 0);
  margin: 0 20rpx;
  height: 88vh;
}

.buttons {
  border: none !important;
}

.flex {
  display: flex;
  border-bottom: 1rpx solid #efefef;
  margin-bottom: 10rpx;

  &:nth-child(2) {
    .item_left {
      width: 77% !important;
    }
  }

  &:last-child {
    border-bottom: none;
  }

  .flex_avater {
    border-radius: 40rpx;
    width: 80rpx;
    height: 80rpx;
    margin: 20rpx 0 0 30rpx;
  }

  .item_left_box {
    .names {
      color: $uni-text-color;
      font-weight: 500;
      font-size: $uni-font-size-big;
    }

    .name {
      color: #999999;
      font-weight: 500;
      font-size: $uni-font-size-sm;
    }
  }

  .item_right {
    margin-top: 50rpx !important;

    .status {
      width: 104rpx;
      height: 36rpx;
      font-family: PingFangSC;
      color: $uni-color-primary;
      font-weight: 500;
      font-size: 22rpx;
      display: flex;
      justify-content: center;
      align-items: center;
      border-radius: 18rpx;
      margin-right: 18rpx;
      background-color: rgba(0, 56, 247, 0.1);
    }

    .blue {
      width: 104rpx;
      height: 36rpx;
      font-family: PingFangSC;
      color: $uni-color-primary;
      font-weight: 500;
      font-size: 22rpx;
      display: flex;
      justify-content: center;
      align-items: center;
      border-radius: 18rpx;
      margin-right: 18rpx;
      background-color: rgba(0, 56, 247, 0.1);
    }

    .gray {
      width: 104rpx;
      height: 36rpx;
      font-family: PingFangSC;
      color: #333;
      font-weight: 500;
      font-size: 22rpx;
      display: flex;
      justify-content: center;
      align-items: center;
      border-radius: 18rpx;
      margin-right: 18rpx;
      background-color: #efefef;
    }

    .yellow {
      width: 104rpx;
      height: 36rpx;
      font-family: PingFangSC;
      color: #F77704;
      font-weight: 500;
      font-size: 22rpx;
      display: flex;
      justify-content: center;
      align-items: center;
      border-radius: 18rpx;
      margin-right: 18rpx;
      background-color: #FEF3E6;
    }

    .green {
      width: 104rpx;
      height: 36rpx;
      font-family: PingFangSC;
      color: #17A500;
      font-weight: 500;
      font-size: 22rpx;
      display: flex;
      justify-content: center;
      align-items: center;
      border-radius: 18rpx;
      margin-right: 18rpx;
      background-color: #EAFEE6;
    }

    .red {
      width: 104rpx;
      height: 36rpx;
      font-family: PingFangSC;
      color: #FF0000;
      font-weight: 500;
      font-size: 22rpx;
      display: flex;
      justify-content: center;
      align-items: center;
      border-radius: 18rpx;
      margin-right: 18rpx;
      background-color: #FEE6E6;
    }
  }

  .item_left_box {
    margin-bottom: 10rpx;
  }

  .box_name {
    color: $uni-text-color;
    font-weight: 500;
   font-size:$uni-font-size-26;
    margin-right: 18rpx;
  }

  .box_content {
    font-family: PingFangSC;
    color: #666666;
    font-weight: 400;
   font-size:$uni-font-size-26;
  }
}
</style>